package com.lp.biz.content.controller;

import com.lp.biz.content.model.query.CourseQuery;
import com.lp.biz.content.model.query.FamousQuery;
import com.lp.biz.content.model.query.ReadingQuery;
import com.lp.biz.content.model.query.StoryQuery;
import com.lp.biz.content.model.vo.*;
import com.lp.biz.content.service.BizCoreContentService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.*;

/**
 * BizCoreContentController
 * @program: backend
 * @author Ke.Song
 * @since 2024-05-31 23:14:47
 */
@RestController
@RequestMapping("/content")
public class BizCoreContentController {

    @Autowired
    private BizCoreContentService contentService;

    /**
     * 获取共读会列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/readings")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult getReadingList(ReadingQuery query) {
        return contentService.getReadingList(query);
    }

    /**
     * 创建共读会
     * @param reading 共读会参数
     * @return 处理结果
     */
    @PostMapping("/readings")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult addReading(@RequestBody @Validated Reading reading) {
        contentService.addOrUpdateReading(reading);
        return CommonResult.success();
    }

    /**
     * 更新共读会
     * @param readingId 共读会id
     * @param reading 共读会参数
     * @return 处理结果
     */
    @PutMapping("/readings/{readingId}")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult updateReading(@PathVariable Integer readingId, @RequestBody @Validated Reading reading) {
        reading.setId(readingId);
        contentService.addOrUpdateReading(reading);
        return CommonResult.success();
    }

    /**
     * 共读会上架/下架
     * @param readingId 共读会id
     * @return 处理结果
     */
    @PutMapping("/readings/{readingId}/display")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult readingDisplay(@PathVariable Integer readingId) {
        contentService.readingDisplay(readingId);
        return CommonResult.success();
    }

    /**
     * 删除共读会
     * @param readingId 共读会id
     * @return 处理结果
     */
    @DeleteMapping("/readings/{readingId}")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult deleteReading(@PathVariable Integer readingId) {
        contentService.deleteReading(readingId);
        return CommonResult.success();
    }

    /**
     * 获取共读会详情
     * @param readingId 共读会id
     * @return 查询结果
     */
    @GetMapping("/readings/{readingId}")
    @PermissionAnnotation(menus = {CONTENT_READING})
    public CommonResult getReading(@PathVariable Integer readingId) {
        return contentService.getReading(readingId);
    }

    /**
     * 添加经典语录
     * @param famous 添加参数
     * @return 处理结果
     */
    @PostMapping("/famous")
    @PermissionAnnotation(menus = {CONTENT_FAMOUS_REM})
    public CommonResult addFamous(@RequestBody@Validated Famous famous) {
        contentService.addOrUpdateFamous(famous);
        return CommonResult.success();
    }

    /**
     * 更新经典语录
     * @param famous 添加参数
     * @return 处理结果
     */
    @PutMapping("/famous/{famousId}")
    @PermissionAnnotation(menus = {CONTENT_FAMOUS_REM})
    public CommonResult updateFamous(@RequestBody@Validated Famous famous, @PathVariable Integer famousId) {
        famous.setId(famousId);
        contentService.addOrUpdateFamous(famous);
        return CommonResult.success();
    }

    /**
     * 获取经典语录
     * @param famousId id
     * @return 查询结果
     */
    @GetMapping("/famous/{famousId}")
    @PermissionAnnotation(menus = {CONTENT_FAMOUS_REM})
    public CommonResult getFamous(@PathVariable Integer famousId) {
        return contentService.getFamous(famousId);
    }

    /**
     * 删除经典语录
     * @param famousId id
     * @return 处理结果
     */
    @DeleteMapping("/famous/{famousId}")
    @PermissionAnnotation(menus = {CONTENT_FAMOUS_REM})
    public CommonResult deleteFamous(@PathVariable Integer famousId) {
        contentService.deleteFamous(famousId);
        return CommonResult.success();
    }

    /**
     * 获取经典语录列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/famous")
    @PermissionAnnotation(menus = {CONTENT_FAMOUS_REM})
    public CommonResult getFamous(FamousQuery query) {
        return contentService.getFamousList(query);
    }

    /**
     * 获取听故事列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/stories")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult getStories(StoryQuery query) {
        return contentService.getStories(query);
    }

    /**
     * 听故事上架/下架
     * @param storyId 故事id
     * @return 处理结果
     */
    @PutMapping("/stories/{storyId}/display")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult displayStory(@PathVariable Integer storyId) {
        contentService.displayStory(storyId);
        return CommonResult.success();
    }

    /**
     * 删除听故事
     * @param storyId 故事id
     * @return 处理结果
     */
    @DeleteMapping("/stories/{storyId}")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult deleteStory(@PathVariable Integer storyId) {
        contentService.deleteStory(storyId);
        return CommonResult.success();
    }

    /**
     * 获取听故事详情
     * @param storyId 故事id
     * @return 查询结果
     */
    @GetMapping("/stories/{storyId}")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult getStory(@PathVariable Integer storyId) {
        return contentService.getStory(storyId);
    }

    /**
     * 创建听故事
     * @param story 听故事参数
     * @return 处理结果
     */
    @PostMapping("/stories")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult addStory(@RequestBody @Validated Story story) {
        contentService.addOrUpdateStory(story);
        return CommonResult.success();
    }

    /**
     * 更新听故事
     * @param story 听故事参数
     * @return 处理结果
     */
    @PutMapping("/stories/{storyId}")
    @PermissionAnnotation(menus = {CONTENT_STORY})
    public CommonResult updateStory(@RequestBody @Validated Story story, @PathVariable Integer storyId) {
        story.setId(storyId);
        contentService.addOrUpdateStory(story);
        return CommonResult.success();
    }

    /**
     * 获取每日听故事列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/daily")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult getDailyStoryList(StoryQuery query) {
        return contentService.getDailyStoryList(query);
    }

    /**
     * 删除每日故事
     * @param storyId 故事id
     * @return 处理结果
     */
    @DeleteMapping("/daily/{storyId}")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult deleteDailyStory(@PathVariable Integer storyId) {
        contentService.deleteDailyStory(storyId);
        return CommonResult.success();
    }

    /**
     * 每日故事上架/下架
     * @param storyId 故事id
     * @return 处理结果
     */
    @PutMapping("/daily/{storyId}/display")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult dailyStoryDisplay(@PathVariable Integer storyId) {
        contentService.dailyStoryDisplay(storyId);
        return CommonResult.success();
    }

    /**
     * 创建每日故事
     * @param daily 每日故事参数
     * @return 处理结果
     */
    @PostMapping("/daily")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult addDailyStory(@RequestBody@Validated Daily daily) {
        contentService.addOrUpdateDailyStory(daily);
        return CommonResult.success();
    }

    /**
     * 更新每日故事
     * @param daily 每日故事参数
     * @param storyId 故事id
     * @return 处理结果
     */
    @PutMapping("/daily/{storyId}")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult updateDailyStory(@RequestBody@Validated Daily daily, @PathVariable Integer storyId) {
        daily.setId(storyId);
        contentService.addOrUpdateDailyStory(daily);
        return CommonResult.success();
    }

    /**
     * 获取每日故事详情
     * @param dailyId 每日故事id
     * @return 处理结果
     */
    @GetMapping("/daily/{dailyId}")
    @PermissionAnnotation(menus = {CONTENT_DAILY_STORY})
    public CommonResult getDailyStory(@PathVariable Integer dailyId) {
        return contentService.getDailyStory(dailyId);
    }

    /**
     * 创建课程
     * @param params 课程参数
     * @return 处理结果
     */
    @PostMapping("/course")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult addCourse(@RequestBody @Validated Course params) {
        contentService.addOrUpdateCourse(params);
        return CommonResult.success();
    }

    /**
     * 更新课程
     * @param params 课程参数
     * @return 处理结果
     */
    @PutMapping("/course/{courseId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult updateCourse(@RequestBody @Validated Course params, @PathVariable Integer courseId) {
        params.setId(courseId);
        contentService.addOrUpdateCourse(params);
        return CommonResult.success();
    }

    /**
     * 获取课程列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/course")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult getCourses(CourseQuery query) {
        return contentService.getCourses(query);
    }

    /**
     * 获取课程详情
     * @param courseId 课程id
     * @return 查询结果
     */
    @GetMapping("/course/{courseId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult getCourseDetail(@PathVariable Integer courseId) {
        return contentService.getCourseDetail(courseId);
    }

    /**
     * 删除课程
     * @param courseId 课程id
     * @return 处理结果
     */
    @DeleteMapping("/course/{courseId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult deleteCourse(@PathVariable Integer courseId) {
        contentService.deleteCourse(courseId);
        return CommonResult.success();
    }

    /**
     * 更新课程上架/下架
     * @param courseId 课程id
     * @return 处理结果
     */
    @PutMapping("/course/{courseId}/display")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult updateCourseStatus(@PathVariable Integer courseId) {
        contentService.updateCourseStatus(courseId);
        return CommonResult.success();
    }

    /**
     * 增加课程章节
     * @param courseId 课程id
     * @param chapter  章节参数
     * @return 处理结果
     */
    @PostMapping("/course/{courseId}/chapter")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult addChapter(@PathVariable Integer courseId, @RequestBody @Validated Chapter chapter) {
        contentService.addOrUpdateChapter(courseId, chapter);
        return CommonResult.success();
    }

    /**
     * 更新课程章节
     * @param courseId 课程id
     * @param chapter  章节参数
     * @return 处理结果
     */
    @PutMapping("/course/{courseId}/chapter/{chapterId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult updateChapter(@PathVariable Integer courseId, @RequestBody @Validated Chapter chapter, @PathVariable Integer chapterId) {
        chapter.setId(chapterId);
        contentService.addOrUpdateChapter(courseId, chapter);
        return CommonResult.success();
    }

    /**
     * 更新章节上架/下架
     * @param chapterId 章节id
     * @return 处理结果
     */
    @PutMapping("/chapter/{chapterId}/display")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult updateChapterStatus(@PathVariable Integer chapterId) {
        contentService.updateChapterStatus(chapterId);
        return CommonResult.success();
    }

    /**
     * 获取章节详情
     * @param chapterId 章节id
     * @return 查询结果
     */
    @GetMapping("/chapter/{chapterId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult getChapterDetail(@PathVariable Integer chapterId) {
        return contentService.getChapterDetail(chapterId);
    }

    /**
     * 获取章节列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/course/{courseId}/chapter")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult getChapterList(PageParams query, @PathVariable Integer courseId) {
        return contentService.getChapterList(query, courseId);
    }

    /**
     * 删除章节
     * @param chapterId 章节id
     * @return 处理结果
     */
    @DeleteMapping("/chapter/{chapterId}")
    @PermissionAnnotation(menus = {CONTENT_COURSE})
    public CommonResult deleteChapter(@PathVariable Integer chapterId) {
        contentService.deleteChapter(chapterId);
        return CommonResult.success();
    }

}
